//
//  MCMainViewController.m
//  MirkoLibTest
//
//  Created by Mirko on 2017/3/20.
//  Copyright © 2017年 Mirko. All rights reserved.
//

#import "MCMainViewController.h"
#import "TSWebInitialViewController.h"
#import "TSInitialInteface.h"
#import "ViewController.h"
#import "TSDefaultCommonViewController.h"
#import "TSDataPickerViewController.h"
#import "TSAutoFillViewController.h"

@interface MCMainViewController ()

@property (nonnull, strong) NSMutableArray<id<TSInitialInteface>> *intefaceObjs;


@property (nonatomic, strong) NSString *testString1;

@end

@implementation MCMainViewController

-(void) setTestString2:(NSString *)testString2
{
    //做你想做的操作
    _testString2 = testString2;
}

-(void) changeTestString1:(NSString *) str
{
    self.testString1 = str;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addRightBttonAction:nil];
    NSMutableArray *titleArr = [NSMutableArray arrayWithObjects:
                                @"DefaultCommonTest",
                                @"TestWebView",
                                @"日期选择",
                                @"DatePicker",
                                @"AutoFill",
                                nil];
    self.mcTableDataSource = titleArr;
    
    self.intefaceObjs = [[NSMutableArray alloc] init];

    [self.intefaceObjs addObject:[TSDefaultCommonViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[TSWebInitialViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[ViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[TSDataPickerViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[TSAutoFillViewController loadIBVCIdentifier:nil]];
    DLOG(@"%@", self.intefaceObjs)
    
    self.testString2 = @"new string";
}

-(void) handleRightBtnAction:(UIButton*) button
{
    [self.intefaceObjs removeAllObjects];
    [self.intefaceObjs addObject:[TSDefaultCommonViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[TSWebInitialViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[ViewController loadIBVCIdentifier:nil]];
    [self.intefaceObjs addObject:[TSDataPickerViewController loadIBVCIdentifier:nil]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mcTableDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DefaultIdentifier"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DefaultIdentifier"];
    }
    
    cell.textLabel.text = self.mcTableDataSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    id <TSInitialInteface> inteface = self.intefaceObjs[indexPath.row];
    [inteface handelAction:self.navigationController];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
